<%@ page language="java" pageEncoding="UTF-8"%>
<HTML>
	<HEAD>
		<meta http-equiv="Content-Language" content="zh-cn">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<LINK href="${pageContext.request.contextPath}/css/Style1.css" type="text/css" rel="stylesheet">
		<script src="${ pageContext.request.contextPath }/js/jquery-1.11.3.min.js" type="text/javascript"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/layDate-v5.0.9/laydate/laydate.js"></script>
		<script type="text/javascript">
		laydate.render({
			  elem: '#user_create_time' //指定元素
			});
		</script>
		<script type="text/javascript">
		$(function(){
			$("#user_phone").blur(function(){
			//	alert(222);
				var phone  = $(this).val();
				var pattern = /^1[34578]\d{9}$/;
				//alert(pattern.test(phone));
				if(!pattern.test(phone)){
					alert("手机号码格式不正确！");
					$(".button_ok").attr("disabled",true);
					$(".button_ok").text("请修改正确的手机号码！");
					
				}
				if(pattern.test(phone)){
					$(".button_ok").text("确定");
					$(".button_ok").attr("disabled",false);
				}
				}
			);
			
			$("#user_name").blur(function(){
				//	alert(222);
					var user_name  = $(this).val();
					
					if(user_name ==""){
						alert("用户名不能为空！");
						$(".button_ok").attr("disabled",true);
						$(".button_ok").text("请填写用户名（真实姓名）！");
						
					}
					else{
						$(".button_ok").text("确定");
						$(".button_ok").attr("disabled",false);
					}
					}
				);
			
		});
		
		
	 	/* 动态获取部门 */
			$(function(){
				$.post("${pageContext.request.contextPath}/AdminUserServlet",{"method":"ajaxDept"},function(data){
					//alert(data);
					var data =eval(data);
					$.each(data,function(i,j){
						//alert(j.dept_name);
						 $("#dept_select").append("<option name='dept_id' value="+j.dept_id+">"+j.dept_name+"</option>"); 
					});
					
				});
			});
			
			//动态获取职位
			$(function(){
				$.post("${pageContext.request.contextPath}/AdminUserServlet",{"method":"ajaxPost"},function(data){
					//alert(data);
					var data =eval(data);
					$.each(data,function(i,j){
					//	alert(j.post_name);
						$("#post_select").append("<option name='post_id' value="+j.post_id+">"+j.post_name+"</option>"); 
					});
					
				});
			}); 
			
		</script>
		
		
	</HEAD>
	
	<body>
	<h1 style="color:red"> ${ msg } </h1>
		<h1 style="color:red" id="msgH1">  </h1>
		<form id="userAction_save_do" name="Form1" action="${pageContext.request.contextPath}/AdminUserServlet?method=addUser" method="post">
			<input type="hidden" name="method" value="save">
			&nbsp;
			<table style="cellSpacing:1; cellPadding:5 width:100%; align:center; bgColor:#eeeeee; border: 1px solid #8ba7e3; border:0;">
				<tr>
					<td class="ta_01" align="center" bgColor="#afd1f3" colSpan="6"
						height="26">
						<strong><STRONG>添加用户</STRONG>
						</strong>
					</td>
				</tr>

				<tr>
					<td width="10%" align="center" bgColor="#f5fafe" class="ta_01">
						姓名：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<input type="text" name="user_name"  id="user_name" class="bg"/>
					</td>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						用户性别：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<select name="user_sex" >
							<option name="user_sex" value="1">男</option>
							<option name="user_sex" value="0">女</option>
						</select>
					</td>
				</tr>
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						部门：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<select name="dept_id" id="dept_select">
							<option >====请选择====</option>
							<!--动态生成部门  -->
							
						</select>

					</td>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						电话：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<input type="text" name="user_phone"  id="user_phone" class="bg"/>
					</td>
				</tr>
				
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						是否是管理员：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<select name="isadmin" >
						<option  name="isadmin" value="0" > 普通用户</option>
						<option  name="isadmin" value="1" > 管理员 </option>
					</select>
					</td>
				<!-- 	<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						创建时间：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<input type="text" id="user_create_time" name="createTime">
					</td> -->
					
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						职位：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="2">
						<select name=post_id id="post_select" >
							<option >====请选择====</option>
						<!-- 	<option name="post_id" value="1">技术部</option> -->
							
							
						</select>

					</td>
				</tr>
			
				<tr>
					<td class="ta_01" style="WIDTH: 100%" align="center"
						bgColor="#f5fafe" colSpan="4">
						<button type="submit" id="userAction_save_do_submit" value="确定" class="button_ok" onclick="return checkForm()">
							&#30830;&#23450;
						</button>
						<script type="text/javascript">
						function checkForm(){
						//	alert(1111);
							var user_name = $("#user_name").val();
							var dept_select =$("#dept_select").val();
							var user_phone =$("#user_phone").val();
							var post_select =$("#post_select").val();
							//alert(post_select);
							if(user_name !=""&&user_phone!=""&&dept_select !="====请选择===="&&post_select !="====请选择===="){
								$("#msgH1").text();
								return true;}
							else{
								$("#msgH1").text("请检查姓名、手机号、部门、职位是否正确！");
								return false;}
			}
		</script>

						<FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
						<button type="reset" value="重置" class="button_cancel">&#37325;&#32622;</button>

						<FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
						<INPUT class="button_ok" type="button" onclick="history.go(-1)" value="返回"/>
						<span id="Label1"></span>
					</td>
				</tr>
			</table>
		</form>
	</body>
</HTML>